@extends('admin.index.layout')

@section('title', $title)

@section('content')
	
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                用户管理
                <small>用户添加</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">用户管理</a></li>
                <li class="active">用户添加</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <!-- left column -->
                <div class="col-md-12">
                    <!-- general form elements -->
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title"><i class="fa fa-fw  fa-user-plus"></i>快速添加</h3>
                        </div><!-- /.box-header -->
                        <!-- form start -->
                        <form role="form" action="{{url('/admin/user/insert')}}" method="post" enctype="multipart/form-data">

                            <div class="box-body">
								@if (count($errors) > 0)
								    <div id="jg" class="alert alert-danger">
								        <ul>
								            @foreach ($errors->all() as $error)
								                <li>{{ $error }}</li>
								            @endforeach
								        </ul>
								    </div>
								@endif
                            {{ csrf_field() }}
                            <div class="row">
                            	<div class="form-group col-md-4">
                                    <label for="exampleInputName">用户名</label>
                                    <input name="name" type="text" class="form-control" id="exampleInputName"
                                           placeholder="用户名6~18位">
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-gorup col-md-4">
                                    <label>用户权限</label>
                                    <select name="auth" class="form-control">
                                        <option value="0">普通用户</option>
                                        <option value="1">管理员</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label for="exampleInputEmail1">邮箱</label>
                                    <input name="email" type="email" class="form-control" id="exampleInputEmail1"
                                           placeholder="邮箱">
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label for="exampleInputPassword1">密码</label>
                                    <input name="password" type="password" class="form-control" id="exampleInputPassword1"
                                           placeholder="密码">
                                </div> 
                            </div>
                            <div class="row">   
                                <div class="form-group col-md-4">
                                    <label for="exampleInputPassword1">确认密码</label>
                                    <input name="repassword" type="password" class="form-control" id="exampleInputPassword1"
                                           placeholder="确认密码">
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label for="exampleInputFile">头像上传</label>
                                    <p id="demo_result"></p>
                                    <input type="file" id="exampleInputFile" name="pic">
                                    <p class="help-block">请上传你的头像</p>
                                </div>
                            </div>
                            </div><!-- /.box-body -->

                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">提交</button>
                                <button type="reset" class="btn btn-default">重置</button>
                            </div>
                        </form>
                    </div><!-- /.box -->

                  

              

                

                </div><!--/.col (left) -->
                <!-- right column -->
        </div>
    </div>

     <script type="text/javascript">
     	window.onload = function()
     	{
             //预览
            var result = document.getElementById("demo_result");
            var input = document.getElementById("exampleInputFile");

            if(typeof FileReader === 'undefined'){
                result.innerHTML = "<p class='warn'>抱歉，你的浏览器不支持 FileReader</p>";
                input.setAttribute('disabled','disabled');
            }else{
                input.addEventListener('change',readFile,false);
            }
            
            function readFile(){
                var file = this.files[0];
                if(!/image\/\w+/.test(file.type)){
                    alert("请确保文件为图像类型");
                    return false;
                }
                var reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = function(e){
                    result.innerHTML = '<img height="100px" src="'+this.result+'" alt=""/>'
                }
            }

     		// alert($);
     		setInterval(function(){
     			$('#jg').fadeOut();
     			
     		}, 2000);

     	}

     </script>
              
@endsection